/**
* 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
* 日    期：2020-02-17
*/
package com.rzico.market.controller;

import com.rzico.annotation.Log;
import com.rzico.base.BaseController;
import com.rzico.base.CommResult;
import com.rzico.market.entity.PhoneProduct;
import com.rzico.market.plugin.phoneBill.DxPhoneXmlUtil;
import com.rzico.market.service.PhoneProductService;
import com.rzico.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 销售单控制层
 *
 * @author Rzico Boot
 * @version 1.0
 * @date 2020-02-17
 */
@Api(description = "豆讯话费商品接口")
@RestController
@RequestMapping("/phoneProduct")
public class PhoneProductController extends BaseController {

    @Autowired
    private PhoneProductService phoneProductService;

    /**
     * 话费商品列表
     *
     * @param name
     * @return
     */
    @Log(desc = "话费商品列表", type = Log.LOG_TYPE.UPDATE)
    @ApiOperation("话费商品列表")
    @PostMapping("/list")
    @ApiImplicitParams({@ApiImplicitParam(name = "mobile", value = "充值手机号码", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "商品名称", dataType = "String", paramType = "query")
    })
    public CommResult<PhoneProduct> list(String mobile, String name) {
        Map<String, Object> params = new HashMap<String, Object>();

        if (StringUtils.isNotEmpty(name)) {
            params.put("name", name);
        }

        if (StringUtils.isNotEmpty(mobile)) {
            params.put("type", DxPhoneXmlUtil.isChinaMobilePhoneNum(mobile));
        }

        params.put("deleted", 0);
        params.put("isMarketable", 1);

        List<PhoneProduct> list = phoneProductService.selectList(params);

        return CommResult.success(list);
    }

}
